package com.waidi.clothespad.fragment;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.waidi.clothespad.R;
import com.waidi.clothespad.common.MyToast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * Created by Administrator on 2019/7/20.
 */

public class FragLineOut extends Fragment {
    private static final String TAG = "FragLineOut";
/*    @BindView(R.id.ll_shaixuan)
    LinearLayout llShaixuan;*/


    @BindView(R.id.webview)
    WebView ll_webview;





    Unbinder unbinder;
    private View view;
    public Context context;
    public LineOutHandler handler = null;
    public static boolean onDetach = false;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.frag_lineout, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();
        initParam();
        initElem();

    }

    public void initParam()
    {
        handler = new LineOutHandler();

    }

    public void initElem()
    {
        ll_webview.getSettings().setJavaScriptEnabled(true);
        ll_webview.loadUrl("http://192.168.100.212/cutvue/index.html");
        //ll_webview.loadUrl("https://www.baidu.com/");
        ll_webview.setWebViewClient(new WebViewClient());

    }

    //自定义handler类
    class LineOutHandler extends Handler {
        @Override
        //接收别的线程的信息并处理
        public void handleMessage(Message msg) {
            Log.i("LineOutHandler",Integer.toString(msg.arg1));

            if(onDetach==true)
                return;
            try
            {
                switch (msg.arg1)
                {
                    case 1:


                        break;
                    case 2:

                    default:
                        break;
                }
            }catch (Exception e)
            {
                e.printStackTrace();
                MyToast.showToast(context,e.toString());
            }
        }
    }



    @Override
    public void onDestroyView()
    {
        onDetach = true;
        super.onDestroyView();
        unbinder.unbind();
    }
}
